import { APlugin } from '../types/common.interface';
import { TableDatas } from '../cors/table-datas';
import { Injectable, PluginInjectable } from '../decorators/inject';
import { Select } from '../cors/select';
import { ExecuteRecord } from '../cors/execute-record';
import { RenderTrigger } from '../cors/render-trigger';
import { FontStyleCommand } from '../commands/font-style';
import { NFont } from '../types/style.interface'
import { Cell } from '../cors/cell';
@Injectable()
@PluginInjectable('FontStylePlugin')
export class FontStylePlugin extends APlugin {
    constructor(
        protected datas: TableDatas,
        protected executeRecord: ExecuteRecord,
        protected renderTrigger: RenderTrigger,
        protected select: Select,
        // protected font: NFont.IFont
    ) {
        super();
    }
    public init() {

    }
    public getSelectCells() {
        let cells: Cell[] = [];
        for(let row = this.select.selected.row; row < this.select.selected.row + this.select.selected.rowspan; row++) {
            let rowInstance = this.datas.getRow(row);
            for(let col = this.select.selected.col; col < this.select.selected.col + this.select.selected.colspan; col++) {
                let merge = this.datas.mergeCell.getMerge(row,col);
                if(merge != null && (merge.row != row || merge.col != col)) {
                    continue;
                }
                let cellInstance = rowInstance.getCell(col);
                cells.push(cellInstance);
            }
        }
        return cells;
    }
    public excute(font: NFont.IFont) {
        let command = new FontStyleCommand(this.datas, this.select.selected, this.renderTrigger, font);
        this.executeRecord.execute(command);
    }
    public destroy() {

    }
}